package com.bus.common.web.springmvc;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.bus.boot.web.FrontContextInterceptor;

@Configuration
public class ConfigFrontConfigurerAdapter extends WebMvcConfigurerAdapter {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(frontContextInterceptor());
		// registry.addInterceptor(frontLocaleInterceptor());
	}

	@Bean
	public FrontContextInterceptor frontContextInterceptor() {
		return new FrontContextInterceptor();
	}

	// @Bean
	// public FrontLocaleInterceptor frontLocaleInterceptor() {
	// return new FrontLocaleInterceptor();
	// }
	//
	// @Bean
	// public CookieLocaleResolver localeResolver() {
	// CookieLocaleResolver localeResolver = new CookieLocaleResolver();
	// localeResolver.setCookieName("cookieName");
	// localeResolver.setCookieMaxAge(-1);
	// return localeResolver;
	// }
	
	@Bean
	public SimpleFreeMarkerViewResolver freemarkerViewResolver() {
		SimpleFreeMarkerViewResolver freemarkerViewResolver = new SimpleFreeMarkerViewResolver();
		freemarkerViewResolver.setContentType("text/html; charset=UTF-8");
		freemarkerViewResolver.setExposeRequestAttributes(false);
		freemarkerViewResolver.setExposeSessionAttributes(false);
		freemarkerViewResolver.setExposeSpringMacroHelpers(true);
		return freemarkerViewResolver;
	}

	@Override
	public void configureViewResolvers(ViewResolverRegistry registry) {
		registry.viewResolver(freemarkerViewResolver());
	}
}
